<template>
  <div class="userInfo">
    <el-button type="primary" @click="jumpAdd"
      >添加<i class="el-icon-plus"></i
    ></el-button>
    <div>
      <el-form :inline="true" :model="query" class="demo-form-inline">
        <el-form-item label="每页展示文件数目">
          <el-select
            v-model="query.pageSize"
            placeholder="每页展示文件数目"
            @change="changesize"
          >
            <el-option label="5" value="5"></el-option>
            <el-option label="10" value="10"></el-option>
            <el-option label="20" value="20"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
    </div>
    <!--filtList 这个用于查找，这样就可以实现效果了 -->
    <el-table :data="tableData.list" style="width: 100%">
      <el-table-column label="用户名" width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.username }}</span>
        </template>
      </el-table-column>
      <el-table-column label="目标院校" width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.tschool }}</span>
        </template>
      </el-table-column>
      <el-table-column label="邮箱" width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.eamil }}</span>
        </template>
      </el-table-column>
      <el-table-column label="QQ" width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.qq }}</span>
        </template>
      </el-table-column>
      <el-table-column label="性别" width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.sex }}</span>
        </template>
      </el-table-column>
      <el-table-column label="手机号" width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.telphone }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)"
          >编辑
          </el-button>
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index , scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      layout="prev, pager, next, jumper"
      :page-size="Number(query.pageSize)"
      :total="tableData.total"
      @current-change="currentchange"
    >
    </el-pagination>
  </div>
</template>

<script>
import { userDelete, userInfo } from "../api/myReq";
export default {
  name: "userInfo",
  data() {
    return {
      /* 用于存储数据和后面页面分页 */
      tableData: {},
      input: "",
      query: {
        page: 1,/* 当前页面 */
        pageSize: 5,
      },
    };
  },
  methods: {
    handleEdit(index, row) {
      this.$router.push("/home/userEdit?id="+row.id);
      // console.log(index, row);id
    },
    handleDelete(index, row) {
      // console.log(index, row);
      userDelete(row.id).then((resp) => {
        this.$message({
          message: resp.data.message,
          duration: 2000,
          type: "success",
        });
      });
      window.location.reload();
    },
    changesize(){
      this.getlist();
    },
    currentchange(val){
      this.query.page = val;
      this.getlist();
    },
    jumpAdd() {
      this.$router.push("/home/adduser");
    },
    getlist(){
        userInfo(this.query).then((resp) => {
        this.tableData = resp.data.data[0];
      });
    }
  },
  mounted(){
    this.getlist();  
    }
};
</script>

<style scoped>
.el-dropdown {
  margin: 0 450px 0 20px;
}
.el-form{
  display: inline-block;
}
</style>